package com.example.administrator.szb.fragments.fragment_forTab.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.szb.R;
import com.example.administrator.szb.fragments.fragment_forTab.home.bean.SeriveList;
import com.example.administrator.szb.http.URLAddress;

import java.util.List;

/**
 * Created by stone on 2018/1/19.
 */

public class Teseadapter extends BaseAdapter {
    private Context context;
    private List list;
    LayoutInflater inflater;
    public Teseadapter(Context context, List list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public  Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView = inflater.inflate(R.layout.item_tese,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        SeriveList seriveList = (SeriveList) getItem(position);
        holder.tv_title.setText(seriveList.getTitle());
        holder.tv_content.setText(seriveList.getContent());
        holder.tv_name.setText(seriveList.getUser_name());
        holder.tv_time.setText(seriveList.getEnd_time());
        Glide.with(context).load(URLAddress.HOST_PORT+seriveList.getHeadimg()).error(R.mipmap.default_header_s).into(holder.img_head);
        return convertView;
    }

    class ViewHolder{
         LinearLayout checkBox_ll;
         TextView tv_title;
         TextView tv_content;
         TextView tv_name;
         TextView tv_time;
        ImageView img_head;
        public ViewHolder(View view){
            img_head = view.findViewById(R.id.img_head);
            checkBox_ll = (LinearLayout) view.findViewById(R.id.checkBox_ll);
            tv_title = (TextView) view.findViewById(R.id.tv_title);
            tv_content = (TextView) view.findViewById(R.id.tv_content);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            tv_time = (TextView) view.findViewById(R.id.tv_time);
        }
    }
}
